<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }

        .w {
            width: 1200px;
            margin: auto;
        }

        .tags {
            width: 100%;
            padding: 10px;
            box-shadow: 0 0 2px 2px #ccc;
            display: flex;
            column-gap: 15px;
        }

        .tags>li {
            list-style: none;
            line-height: 20px;
            padding: 5px;
            background-color: aliceblue;
            cursor: pointer;
            user-select: none;
        }
        .tags>.checked{
            background-color: red;
            color: white;
        }
        .active {
            color: #FFF;
            background-color: red;
        }

        .container {
            width: 100%;
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
        }
        .box{
            width: 220px;
            padding: 10px;
            display: flex;
            flex-direction: column;
            row-gap: 15px;
            box-shadow: 0 0 2px 2px #ccc;
        }
        .box>img{
            width: 100%;
            aspect-ratio: 22/29;
        }
        /* .container li {
            list-style: none;
            flex-basis: 200px;
            flex-grow: 1;
            height: fit-content;
            padding: 10px;
            box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
            text-align: center;
            cursor: pointer;
        }

        .container li img {
            width: 100%;
        }

        .container li h4 {
            margin: 10px;
        }

        .link {
            text-decoration: none;
            border: 1px solid red;
            display: inline-block;
            width: 100px;
            height: 36px;
            text-align: center;
            line-height: 36px;
            color: red;
        }

        .container li:hover>.link {
            background-color: red;
            color: #FFF,
        } */
    </style>
</head>

<body>
    <main class="main">
        <ul class="tags">
            <!-- <li>z赘婿</li>
            <li>宴请</li>
            <li>小说</li> -->
        </ul>
        <hr>
        <div class="container">
            <div class="box">
                <img src="" alt="">
                <h4>绅士游戏</h4>
                <div>
                    绅士游戏
                </div>
            </div>
        </div>
    </main>

    <script src="./axios.min.js"></script>
    <script>
        let btn = document.querySelector('#btn')
        let tags = document.querySelector('.tags')
        let container = document.querySelector('.container')
        // console.log(lis);
        axios({
            url: "http://playlet.zonelian.com/api/category/list",
            method: 'GET',
            params: {
                zlsj: 'zlsj'
            }
        }).then(res => {
            let list = res.data.data.data
            // console.log(res);
            console.log(res.data.data.data);
            list.forEach((item, index) => {
                let li = document.createElement('li')
                tags.appendChild(li)
                li.innerText = item.name
                li.dataset.name = item.name_en
                if (index == 9) {
                    li.className = 'checked'
                    getMovie(item.name_en)
                }
            })
        })
        tags.addEventListener('click', event=>{
            let tg = event.target
            let lis = document.querySelectorAll('li')
            if (tg.tagName == 'LI') {
                lis.forEach(li => {
                    li.className = ''
                })
                tg.className = 'checked'
                let nameEn = tg.dataset.name
                getMovie(nameEn)
            }

        })
        function getMovie(nameEn) {
            axios({
                url: "http://playlet.zonelian.com/api/playlet/list",
                method: 'GET',
                params: {
                    name_en: nameEn,
                    zlsj: 'zlsj'
                }
            }).then(res => {
                let movieList = res.data.data.data
                let html = ''
                movieList.forEach(item => {
                    html += `
                        <div class="box">
                          <img src="${item.img}" alt="">
                            <h4>${item.title}</h4>
                        <div>${item.description}</div>
                        </div>
                    `
                })
                container.innerHTML = html
            })
        }
    </script>
</body>

</html>